package com.pingan.license.listener;

import com.pingan.license.authority.LicenseVertify;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @AUTHOR:LIUCHAO;
 * @DATE: 2020/12/1 19:43
 */
@Component
public class LicenseCheckListener implements ApplicationListener {
    private static Logger logger = LogManager.getLogger(LicenseCheckListener.class);
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        //root application context 没有parent
        ContextRefreshedEvent event= (ContextRefreshedEvent) applicationEvent;
        ApplicationContext context = event.getApplicationContext().getParent();
        if(context == null){
            LicenseVertify vlicense=new LicenseVertify("pingan");
            vlicense.install(System.getProperty("user.dir"));
//        vlicense.vertify();
            boolean verify = vlicense.verify();
            System.out.println("校验证书"+verify);

        }
    }
}
